package src

func SafeClose(ch chan int) (justClosed bool) {
	if ch == nil {
		return
	}

	defer func() {
		if recover() != nil {
			justClosed = false
		}
	}()

	close(ch) // panic if ch is closed
	return true
}

func SafeSend(ch chan int, value int) (closed bool) {
	defer func() {
		if recover() != nil {
			// The return result can be altered
			// in a defer function all.
			closed = true
		}
	}()

	ch <- value // panic if ch is closed
	return false
}
